<?php

class WebSetController extends AuthController {
	private $model;

	public function __init() {
		parent::__init();
		$this -> model = M('config');
	}

	public function index() {
		$configs1 = $this -> model -> where('type_id=1') -> all();
		$configs2 = $this -> model -> where('type_id=2') -> all();
		$configs3 = $this -> model -> where('type_id=3') -> all();
		$configs4 = $this -> model -> where('type_id=4') -> all();
		$this -> assign('configs1', $configs1);
		$this -> assign('configs2', $configs2);
		$this -> assign('configs3', $configs3);
		$this -> assign('configs4', $configs4);
		$this -> display();
	}

	/**
	 * 修改方法
	 */
	public function updates() {
				
		if (IS_POST) {
			//将配置文件写入数据库
				foreach(Q('post.') as $key=>$val){
					$this->model->where("name='{$key}'")->update(array("value"=>$val));
				}
//				
			
			
			//再将配置信息写入配置文件中
			$configs = $this->model->all();
			$config = array();
			foreach($configs as $val){
				$config[$val['name']] = $val['value'];
			}
			$config = var_export($config,true);
			$str=<<<str
<?php
if (!defined("HDPHP_PATH"))exit('No direct script access allowed');
return {$config}
?>
str;
		 	file_put_contents(APP_CONFIG_PATH.'WebConfig.php',$str);
			$this->success('修改成功');
		}

	}
}
